<?php
header("Content-Type: application/json charset=UTF-8");

$connect = mysqli_connect('localhost','root','root','22mysql');
if (!$connect) {
    echo json_encode(['code' => 0, 'msg' => '数据库连接失败']);
}
$sql = "SELECT money,year,moon FROM money where yg_id = 2 and  year = 2024 ";
$query = mysqli_query($connect,$sql);
$data = mysqli_fetch_all($query,MYSQLI_ASSOC);

$x = [];
$y = [];
foreach ($data as $val) {
    $x[] = $val['year']. '-'.$val['moon'] ;
    $y[] = $val['money'];
}

echo json_encode(['code' => 1, 'msg' => '查询成功', 'data' => [
    'x' => $x,
    'y' => $y
]]);
